/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import vn.com.fis.portal.model.ContactGroupEntry;
import vn.com.fis.portal.model.ContactGroupEntryModel;
import vn.com.fis.portal.model.ContactGroupEntrySoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.List;

/**
 * The base model implementation for the ContactGroupEntry service. Represents a row in the &quot;TBL_CONTACT_GROUP&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link vn.com.fis.portal.model.ContactGroupEntryModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ContactGroupEntryImpl}.
 * </p>
 *
 * @author loind
 * @see ContactGroupEntryImpl
 * @see vn.com.fis.portal.model.ContactGroupEntry
 * @see vn.com.fis.portal.model.ContactGroupEntryModel
 * @generated
 */
@JSON(strict = true)
public class ContactGroupEntryModelImpl extends BaseModelImpl<ContactGroupEntry>
	implements ContactGroupEntryModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a contact group entry model instance should use the {@link vn.com.fis.portal.model.ContactGroupEntry} interface instead.
	 */
	public static final String TABLE_NAME = "TBL_CONTACT_GROUP";
	public static final Object[][] TABLE_COLUMNS = {
			{ "contactGroupId", Types.BIGINT },
			{ "contactGroupName", Types.VARCHAR },
			{ "description", Types.VARCHAR },
			{ "contactGroupType", Types.INTEGER },
			{ "userId", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table TBL_CONTACT_GROUP (contactGroupId LONG not null primary key,contactGroupName VARCHAR(75) null,description VARCHAR(75) null,contactGroupType INTEGER,userId LONG)";
	public static final String TABLE_SQL_DROP = "drop table TBL_CONTACT_GROUP";
	public static final String ORDER_BY_JPQL = " ORDER BY contactGroupEntry.contactGroupName ASC";
	public static final String ORDER_BY_SQL = " ORDER BY TBL_CONTACT_GROUP.contactGroupName ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.vn.com.fis.portal.model.ContactGroupEntry"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.vn.com.fis.portal.model.ContactGroupEntry"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.vn.com.fis.portal.model.ContactGroupEntry"),
			true);
	public static long CONTACTGROUPID_COLUMN_BITMASK = 1L;
	public static long USERID_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static ContactGroupEntry toModel(ContactGroupEntrySoap soapModel) {
		ContactGroupEntry model = new ContactGroupEntryImpl();

		model.setContactGroupId(soapModel.getContactGroupId());
		model.setContactGroupName(soapModel.getContactGroupName());
		model.setDescription(soapModel.getDescription());
		model.setContactGroupType(soapModel.getContactGroupType());
		model.setUserId(soapModel.getUserId());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<ContactGroupEntry> toModels(
		ContactGroupEntrySoap[] soapModels) {
		List<ContactGroupEntry> models = new ArrayList<ContactGroupEntry>(soapModels.length);

		for (ContactGroupEntrySoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.vn.com.fis.portal.model.ContactGroupEntry"));

	public ContactGroupEntryModelImpl() {
	}

	public long getPrimaryKey() {
		return _contactGroupId;
	}

	public void setPrimaryKey(long primaryKey) {
		setContactGroupId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_contactGroupId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return ContactGroupEntry.class;
	}

	public String getModelClassName() {
		return ContactGroupEntry.class.getName();
	}

	@JSON
	public long getContactGroupId() {
		return _contactGroupId;
	}

	public void setContactGroupId(long contactGroupId) {
		_columnBitmask |= CONTACTGROUPID_COLUMN_BITMASK;

		if (!_setOriginalContactGroupId) {
			_setOriginalContactGroupId = true;

			_originalContactGroupId = _contactGroupId;
		}

		_contactGroupId = contactGroupId;
	}

	public long getOriginalContactGroupId() {
		return _originalContactGroupId;
	}

	@JSON
	public String getContactGroupName() {
		if (_contactGroupName == null) {
			return StringPool.BLANK;
		}
		else {
			return _contactGroupName;
		}
	}

	public void setContactGroupName(String contactGroupName) {
		_columnBitmask = -1L;

		_contactGroupName = contactGroupName;
	}

	@JSON
	public String getDescription() {
		if (_description == null) {
			return StringPool.BLANK;
		}
		else {
			return _description;
		}
	}

	public void setDescription(String description) {
		_description = description;
	}

	@JSON
	public int getContactGroupType() {
		return _contactGroupType;
	}

	public void setContactGroupType(int contactGroupType) {
		_contactGroupType = contactGroupType;
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_columnBitmask |= USERID_COLUMN_BITMASK;

		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ContactGroupEntry toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (ContactGroupEntry)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					ContactGroupEntry.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		ContactGroupEntryImpl contactGroupEntryImpl = new ContactGroupEntryImpl();

		contactGroupEntryImpl.setContactGroupId(getContactGroupId());
		contactGroupEntryImpl.setContactGroupName(getContactGroupName());
		contactGroupEntryImpl.setDescription(getDescription());
		contactGroupEntryImpl.setContactGroupType(getContactGroupType());
		contactGroupEntryImpl.setUserId(getUserId());

		contactGroupEntryImpl.resetOriginalValues();

		return contactGroupEntryImpl;
	}

	public int compareTo(ContactGroupEntry contactGroupEntry) {
		int value = 0;

		value = getContactGroupName()
					.compareTo(contactGroupEntry.getContactGroupName());

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		ContactGroupEntry contactGroupEntry = null;

		try {
			contactGroupEntry = (ContactGroupEntry)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = contactGroupEntry.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		ContactGroupEntryModelImpl contactGroupEntryModelImpl = this;

		contactGroupEntryModelImpl._originalContactGroupId = contactGroupEntryModelImpl._contactGroupId;

		contactGroupEntryModelImpl._setOriginalContactGroupId = false;

		contactGroupEntryModelImpl._originalUserId = contactGroupEntryModelImpl._userId;

		contactGroupEntryModelImpl._setOriginalUserId = false;

		contactGroupEntryModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<ContactGroupEntry> toCacheModel() {
		ContactGroupEntryCacheModel contactGroupEntryCacheModel = new ContactGroupEntryCacheModel();

		contactGroupEntryCacheModel.contactGroupId = getContactGroupId();

		contactGroupEntryCacheModel.contactGroupName = getContactGroupName();

		String contactGroupName = contactGroupEntryCacheModel.contactGroupName;

		if ((contactGroupName != null) && (contactGroupName.length() == 0)) {
			contactGroupEntryCacheModel.contactGroupName = null;
		}

		contactGroupEntryCacheModel.description = getDescription();

		String description = contactGroupEntryCacheModel.description;

		if ((description != null) && (description.length() == 0)) {
			contactGroupEntryCacheModel.description = null;
		}

		contactGroupEntryCacheModel.contactGroupType = getContactGroupType();

		contactGroupEntryCacheModel.userId = getUserId();

		return contactGroupEntryCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(11);

		sb.append("{contactGroupId=");
		sb.append(getContactGroupId());
		sb.append(", contactGroupName=");
		sb.append(getContactGroupName());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append(", contactGroupType=");
		sb.append(getContactGroupType());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(19);

		sb.append("<model><model-name>");
		sb.append("vn.com.fis.portal.model.ContactGroupEntry");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>contactGroupId</column-name><column-value><![CDATA[");
		sb.append(getContactGroupId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>contactGroupName</column-name><column-value><![CDATA[");
		sb.append(getContactGroupName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>contactGroupType</column-name><column-value><![CDATA[");
		sb.append(getContactGroupType());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = ContactGroupEntry.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			ContactGroupEntry.class
		};
	private long _contactGroupId;
	private long _originalContactGroupId;
	private boolean _setOriginalContactGroupId;
	private String _contactGroupName;
	private String _description;
	private int _contactGroupType;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private transient ExpandoBridge _expandoBridge;
	private long _columnBitmask;
	private ContactGroupEntry _escapedModelProxy;
}